package YAPserver.logic;

import java.util.ArrayList;
import java.util.Observable;

import YAPenvironment.YAPconstant;
import YAPserver.gameObjects.GameBall;
import YAPserver.gameObjects.Mod;
import YAPserver.gameObjects.Slider;
import YAPserver.gameObjects.GameWall;

public class GameState extends Observable {
	String m_objectPos;
	String m_playerStat;
	String n = YAPconstant.C_NEWLINE;
	String sep = YAPconstant.C_SEPARATOR;
	
	GameState(Output out){
		this.addObserver(out);
	}
	
	/**
	 * Creates a new string of all the positions of the different gameObjects in the game.
	 * @param sliders arrayList of sliders
	 * @param balls arrayList of gameBalls
	 * @param mods arrayList of mods that are still moving
	 * @param walls arrayList of walls (even ones that belong to a player)
	 */
	public void updateObjectPos(ArrayList<Slider> sliders, ArrayList<GameBall> balls,
			ArrayList<Mod> mods, ArrayList<GameWall> walls){
		m_objectPos = "";
		//first write the sliders
		for(int i=0; i<sliders.size(); i++){
			m_objectPos = m_objectPos + sliders.get(i) + sep;
		}
		m_objectPos = m_objectPos + n;
		//now write the Balls
		for(int i=0; i<balls.size(); i++){
			m_objectPos = m_objectPos + balls.get(i) + sep;
		}
		m_objectPos = m_objectPos + n;
		//now write the Mods
		for(int i=0; i<mods.size(); i++){
			m_objectPos = m_objectPos + mods.get(i) + sep;
		}
		m_objectPos = m_objectPos + n;
		//now write the visible walls
		for(int i=0; i<walls.size(); i++){
			m_objectPos = m_objectPos + walls.get(i).stringColour() + sep;
		}
		this.setChanged();
		this.notifyObservers("objectPos");
	}
	
	/**
	 * Returns a string of all the positions of the different gameObjects in the game.
	 * @return a string of all the positions of the different gameObjects in the game
	 */
	public String getObjectPos(){
		return m_objectPos;
	}
	
//	public void updatePlayerStat(HashMap<Integer, Player> players){
//		m_playerStat = "";
//		for(int id : players.keySet()){
//			m_playerStat = m_playerStat + players.get(id) + sep;
//		}
//		this.setChanged();
//		this.notifyObservers("playerStat");
//	}
	
	/**
	 * Returns a string of the player's id and lives.
	 * @return a string of the player's id and lives
	 */
	public String getPlayerStat(){
		return m_playerStat;
	}
}
